<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no" />
		<meta content="yes" name="apple-mobile-web-app-capable">
		<meta content="black" name="apple-mobile-web-app-status-bar-style">
		<meta content="telephone=no" name="format-detection">
		<title>盛夏自驾 酷爽一夏</title>
		<script>
			(function(doc, win) {
				var docEl = doc.documentElement,
					resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
					recalc = function() {
						var clientWidth = docEl.clientWidth;
						if (!clientWidth) return;
						var fontSize = 100 * (clientWidth / 750);
						docEl.style.fontSize = (fontSize > 100 ? 100 : fontSize) + 'px';
					};
				recalc();
				if (!doc.addEventListener) return;
				win.addEventListener(resizeEvt, recalc, false);
				doc.addEventListener('DOMContentLoaded', recalc, false);
			})(document, window);
		</script>
		<script type="text/javascript" src="https://cms.dafang24.com/js/jquery-1.7.2.min.js"></script>
		<script type="text/javascript" src="https://appx/web-view.min.js"></script>
		<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>
		<script type="text/javascript" src="https://b.bdstatic.com/searchbox/icms/searchbox/js/swan-2.0.21.js"></script>
		<style>
			html,
			body,
			h1,
			h2,
			h3,
			h4,
			h5,
			h6,
			p,
			ul,
			li,
			img,
			a {
				margin: 0;
				padding: 0;
				/*font-size: .2rem;*/
				color: #515151;
			}
		
			body {
				margin: 0 auto;
				padding: 0;
				max-width: 1080px;
				min-width: 320px;
				background: #f3f3f3;
			}
		
			img {
				border: none;
				vertical-align: top;
			}
		
			ul,
			li {
				list-style-type: none;
			}
		
			input[type=buttton] {
				-webkit-appearance: none;
			}
		
			input[type=text] {
				-webkit-appearance: none;
				border-radius: 0
			}
		
			input:focus {
				outline: 0
			}
		
			a {
				text-decoration: none;
				-webkit-tap-highlight-color: transparent;
			}
		
			a:link,
			a:active,
			a:visited {
				text-decoration: none;
			}
		
			.dHeader {
				width: 100%;
				max-width: 1080px;
				height: 1.0rem;
				line-height: 1.0rem;
				text-align: center;
				font-size: .34rem;
				font-weight: bold;
				position: fixed;
				top: 0;
				left: 50%;
				transform: translateX(-50%);
				z-index: 999;
				background-color: #fff;
				border-bottom: 1px solid #ddd;
				box-sizing: border-box;
				display: none;
			}
		
			.dHeader a {
				display: block;
				width: 1rem;
				height: 1.0rem;
				position: absolute;
				top: 0;
				left: 0;
				background: url('https://cms.dafang24.com/js/backIcon.png') no-repeat center;
				background-size: 0.5rem auto;
			}
		
			.noLogin {
				position: fixed;
				top: 42%;
				left: 0;
				width: 100%;
				text-align: center;
				font-size: .4rem;
				display: none;
			}
		
			.noLogin span {
				padding: 0.18rem 1.2rem;
				border-radius: .1rem;
				background-color: rgba(0, 0, 0, .6);
				color: #fff;
			}
		</style>
		<style>
			.app {
				width: 100%;
			}
		
			.app .bg {
				width: 100%;
			}
		
			.btnsBox {
				position: relative;
			}
		
			.btnsBox .btn {
				display: block;
				/*background-color: rgba(0,0,0,0.4);*/
				position: absolute;
			}
		
			.btnsBox .btn04 {
				    width: 95%;
				    height: 2.9rem;
				    right: 2.5%;
				    top: 3.6rem
			}
		
			/* .btnsBox .btn01 {
				width: 2.4rem;
				height: 2.9rem;
				right: 10%;
				top: 0.3rem;
			}
		
			.btnsBox .btn02 {
				width: 95%;
				height: 1.8rem;
				right: 2.5%;
				top:8.4rem;
			} */
		</style>
	</head>
	<body>
		<div class="dHeader">
			<a href="javascript:void(0);"></a>
			  盛夏自驾 酷爽一夏
		</div>
		<div class="app">
			<div>
				<img class="bg" src="./img/summer_app.png">
			</div>
			<div class="btnsBox">
				<img class="bg" src="./img/summer_app_02.png">
				<a href="javascript:void(0);" class="btn btn04"></a>
			</div>
			<div>
				<img class="bg" src="./img/summer_app_03.png">
			</div>
			<div class="btnsBox">
				<img class="bg" src="./img/summer_app_04.png">
				<!-- <a href="javascript:void(0);" class="btn btn02"></a> -->
			</div>
			<div>
				<img class="bg" src="./img/summer_app_05.png">
			</div>
			<!-- 错误信息 -->
			<div class="noLogin"><span></span></div>
		</div>
		<script>
			var _userAgent = navigator.userAgent
			var isDrawCoupon = {
				couponList: [{
						name: "盛夏满2000元，减240元。",
						OfferID: 531
					},
					{
						name: "盛夏满1000元，减120元。",
						OfferID: 530
					},
					{
						name: "盛夏满500元，减60元。",
						OfferID: 529
					}
				],
			};
			$(function() {
				if (/AlipayClient/.test(_userAgent)) { //支付宝
		
				} else if (/swan\//.test(_userAgent) || /^webswan-/.test(window.name)) { //H5
		
				} else {
					if (/MicroMessenger/.test(_userAgent)) { //
						// if( wx ){
						//     wx.miniProgram.getEnv(res => {
						//         if (res.miniprogram) {
						//             $('.dHeader').show();
						//             $('.app').css({ "position": "relative","top": "1rem"});
						//         }
						//     })
						// }
					} else {
						$('.dHeader').show();
						$('.app').css({
							"position": "relative",
							"top": "1rem"
						});
					}
				}
				$('.btnsBox .btn04').click(function() {
					var obj1 = isDrawCoupon.couponList;
					getCoupon(obj1);
					// console.log(11111)
				});
			});
		
			var token = getQueryVariable("token");
			var getConsumerCoupons = "https://api.new.dafang24.com:442/api/Offer/GetConsumerOwnCoupons"; //获取用户优惠券
			var drawFitableCoupon = "https://api.new.dafang24.com:442/api/Offer/DrawCoupon"; //领取优惠券
			var nowTime = 0,
				lastTime = 0;
		
			function goBack() {
				if (/AlipayClient/.test(_userAgent)) { //支付宝
					if (my) {
						my.switchTab({
							url: '/pages/rent/shortrent/shortrent'
						});
						return;
					}
					window.location.href = document.referrer || 'http://m.dafang24.com';
				} else if (/swan\//.test(_userAgent) || /^webswan-/.test(window.name)) { //H5
					if (swan) {
						swan.webView.switchTab({
							url: '/pages/rent/shortrent/shortrent'
						});
						return;
					}
					window.location.href = document.referrer || 'http://m.dafang24.com';
				} else {
					if (/MicroMessenger/.test(_userAgent)) { //
						if (wx) {
							wx.miniProgram.switchTab({
								url: '/pages/rent/shortrent/shortrent'
							});
							return;
						}
						window.location.href = document.referrer || 'http://m.dafang24.com';
					} else {
						if (document.referrer) {
							window.history.go(-1)
						} else {
							window.location.href = 'http://m.dafang24.com'
						}
					}
				}
			}
		
			function getCoupon(obj) {
				nowTime = Date.parse(new Date());
				if (!lastTime || nowTime - lastTime > 1500) {
					lastTime = nowTime;
					// 判断是否是支付宝小程序
					if (/AlipayClient/.test(_userAgent)) {
						if (my) {
							let arr = {
								isDrawCoupon: {
									couponList: obj
								}
							};
							my.postMessage(arr);
						}
					} else {
						$.ajax({
							url: getConsumerCoupons,
							type: 'GET',
							dateType: 'json',
							headers: {
								'token': token
							},
							data: null,
							success: function(res) {
								console.log(res)
								if (typeof res == 'string') {
									res = JSON.parse(res)
								}
								if (res.Code == 100) {
									var _couponList = obj;
									for (var i = 0; i < _couponList.length; i++) {
										for (var j = 0; j < res.Data.length; j++) {
											if (_couponList.length && (_couponList[i].OfferID == res.Data[j].OfferID)) {
												_couponList.splice(i, 1);
											}
										}
									}
									if (_couponList.length) {
										for (var i = 0; i < _couponList.length; i++) {
											$.ajax({
												url: drawFitableCoupon,
												type: 'GET',
												dateType: 'json',
												headers: {
													'token': token
												},
												data: {
													OfferID: _couponList[i].OfferID,
													orgID: 0
												},
												success: function(ress) {
													if (typeof ress == 'string') {
														ress = JSON.parse(ress)
													}
													if (ress.Code == 100) {
														showTips('领取成功！去租车吧~', function() {
															// history.go(-1);
															if (/MicroMessenger/.test(
																_userAgent)) {
																// wx.miniProgram.redirectTo({
																//   url: '/pages/rent/rent'
																// });
															} else {
																// history.go(-1);
															}
														});
													} else {
														showTips(ress.Message);
													}
												},
												error: function(error) {
													showTips('请求失败，请重试!');
												}
											})
										}
									} else {
										showTips('领取成功！去租车吧~', function() {
											// history.go(-1);
											if (/MicroMessenger/.test(_userAgent)) {
												// wx.miniProgram.redirectTo({
												//   url: '/pages/rent/rent'
												// });
											} else {
												// history.go(-1);
											}
										});
									}
								} else if (res.Code == 17007) {
									var _pathname = 'https://cms.dafang24.com/aliapp/pages/20210615/roadTrip.html';
									showTips('请先登录/注册！', function() {
										if (/MicroMessenger/.test(_userAgent)) {
											wx.miniProgram.getEnv(res => {
												if (res.miniprogram) {
													wx.miniProgram.navigateTo({
														url: `/pages/user/authLogin/authLogin?all_uri=${_pathname}`
													});
												} else {
													// location.href = 'https://m.dafang24.com:448/normalLogin?all_uri='+_pathname
													location.href =
														'https://m.dafang24.com:448/normalLogin?all_uri=' +
														_pathname
												}
											});
											return;
										}
										if (/swan\//.test(window.navigator.userAgent) || /^webswan-/.test(
												window.name)) {
											swan.webView.navigateTo({
												url: '/pages/user/authLogin/authLogin'
											});
											return;
										}
										location.href = 'https://m.dafang24.com:448/normalLogin?all_uri=' +
											_pathname
										// history.go(-1);
									});
								} else {
									console.log(res)
									showTips(res.Message);
								}
							},
							error: function(data) {
								showTips('请求失败，请重试！');
							}
						})
					}
				}
			}
			var timer = null;
		
			function showTips(str, callback) {
				if (timer) {
					clearTimeout(timer);
					timer = null
				}
				$('.noLogin span').html(str);
				$('.noLogin').show();
				timer = setTimeout(function() {
					$('.noLogin').hide();
					if (callback) {
						callback()
					}
				}, 1500)
			}
		
			function getQueryVariable(name) {
				// 构造一个含有目标参数的正则表达式对象
				var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
				// 匹配目标参数
				var r = window.location.search.substr(1).match(reg);
				// 返回参数值
				if (r != null) {
					return decodeURI(r[2]);
				}
				return null;
			}
		</script>
	</body>
</html>
